/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PesquisaObjeto.java
 *
 * Created on 31/03/2013, 23:04:26
 */

package com.bs.pesquisaView;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author Bone
 */
public class PesquisaObjeto extends PesquisaAbstrata {
    private String consulta = "";
    private String campoPesquisa = "";
    
    /** Creates new form PesquisaObjeto */
    public PesquisaObjeto() {
        initComponents();
        legenda.setText(getLegenda());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        caracterFiltro = new com.bs.extensoesSwing.DocumentFilter();
        campoSugestao = new com.bs.extensoesSwing.CampoSugestao();
        legenda = new javax.swing.JLabel();

        campoSugestao.setCampoRetorno("id");
        campoSugestao.setFilter(caracterFiltro);
        campoSugestao.setParametro("parametro");

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${legenda}"), legenda, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(legenda)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(campoSugestao, javax.swing.GroupLayout.DEFAULT_SIZE, 322, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(legenda)
                .addComponent(campoSugestao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        bindingGroup.bind();
    }// </editor-fold>//GEN-END:initComponents

    @Override
    public Criterion getCriterion() {
        if(campoSugestao.getItemSelecionado() == null){
            return null;
        }
        return Restrictions.eq(getCampo(), campoSugestao.getItemSelecionado());
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private com.bs.extensoesSwing.CampoSugestao campoSugestao;
    private com.bs.extensoesSwing.DocumentFilter caracterFiltro;
    private javax.swing.JLabel legenda;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

    public String getCampoPesquisa() {
        return campoPesquisa;
    }

    public void setCampoPesquisa(String campoPesquisa) {
        this.campoPesquisa = campoPesquisa;
        campoSugestao.setCampo(campoPesquisa);
    }

    public String getConsulta() {
        return consulta;
    }

    public void setConsulta(String consulta) {
        this.consulta = consulta;
        campoSugestao.setsQuery(consulta);
    }
    
}
